function amaxvar = randargminVar(vbeta, top, prob)
       global n Vstar

       %need to pass apropriate function handle!!!
       
       %no of draws needed to be in "top" share of designs with proba at
       %least prob
       Ndraws = ceil(log(1-prob) / log(1-top));
        
        
       Dstar=zeros(n,1);
       d=zeros(n,1);
       Vstar=vbeta(Dstar);
       
       k=0; 
       for j=1:Ndraws
           %taking care of limits in matlab random number generators...
           while k<n
               ni=min(50, n-k);
               i=randi(2^ni)-1;
               d(k+1:min(k+50,n))= de2bi(i, ni);
               k=k+50;
           end
           k=0; 
           vnew = vbeta(d);
           if vnew < Vstar
               Dstar=d;                       
               Vstar=vnew; 
           end
       end     

amaxvar=Dstar;       

return
